<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019\2\22 0022
 * Time: 20:50
 */

namespace app\admin\controller;
use think\Controller;
use think\captcha\Captcha;



class Login extends Controller
{
    public function login()
    {
        if(request()->isPost()){
            $chkcode= input('chkcode');
            $captcha = new Captcha();
            $result=$captcha->check($chkcode);
            if($result===false){
                $this->error('验证码错误!');
            }
            $username= input('username');
            $password= md5(input('password'));
            $adminData=db('admin')->where(array('username'=>$username))->find();
            if($adminData){
                  if($adminData['password']==$password){
                      session('username',$username);
                      $this->success('成功登陆!','index/index');
                  }else{
                      $this->error('密码错误!');

                  }
            }else{
                $this->error('用户名错误!');
            }

        }
        return view();
    }
    public function verify()
    {
        $captcha = new Captcha();
        $captcha->imageW=121;
        $captcha->imageH = 32;  //图片高
        $captcha->fontSize =14;  //字体大小
        $captcha->length   = 4;  //字符数
        $captcha->fontttf = '5.ttf';  //字体
        $captcha->expire = 30;  //有效期
        $captcha->useNoise = false;  //不添加杂点
        return $captcha->entry();

    }
    public function logout(){
        session(null);
        $this->redirect('login');
    }
}